1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Drawing;
5 using System.Data;
6 using System.Linq;
7 using System.Text;
8 using System.Threading.Tasks;
9 using System.Windows.Forms;
10 using System.Globalization;
11
12 namespace SoftQuanLyNhaHang.Views
13 {
14 public partial class uctBaoCao_HienThi : UserControl
15 {
16 public uctBaoCao_HienThi()
17 {
18 InitializeComponent();
19 }
20
21 public static uctBaoCao_HienThi uctBC_Ht = new uctBaoCao_HienThi();
22
23 private void ComBoBox_TienHoaHong()
24 {
25 Dictionary<string, string> comboSource = new Dictionary<string, string>();
26 comboSource.Add("0", "-- Hôm nay --");
27 comboSource.Add("1", "-- Ngày hôm qua --");
28 comboSource.Add("2", "-- 7 ngày qua --");
29 comboSource.Add("3", "-- Tuần này --");
30 comboSource.Add("4", "-- Tháng này --");
31 comboSource.Add("5", "-- Tháng trước --");
32 comboSource.Add("6", "-- Năm nay --");
33 comboSource.Add("7", "-- Năm trước --");
34
35 //cmbTienHoaHong_PhamViNgay.DataSource = new BindingSource(comboSource, null);
36 //cmbTienHoaHong_PhamViNgay.DisplayMember = "Value";
37 //cmbTienHoaHong_PhamViNgay.ValueMember = "Key";
38 }
39
40 public void HienThiUct_Bc_Ht(int tPage)
41 {
42 this.HienThiThang_ComboXBox();
43 cmbThangThuChi.SelectedValue = DateTime.Now.Month.ToString();
44 maskedTxt_NamThuChi.Text = DateTime.Now.Year.ToString();
45
46 switch (tPage)
47 {
48 case 1:
49 this.DanhSachThuChiCuaCuaHang();
50
51 tabControlBaoCao_hienThi.SelectedTab = tabPageChiPhi;
52 break;
53 case 2:
54
55 tabControlBaoCao_hienThi.SelectedTab = tabPageBaoCao_tonKho;
56 break;
57 }
58
59 }
60
61 private void HienThiThang_ComboXBox()
62 {
63 Dictionary<string, string> comboSource = new Dictionary<string, string>();
64 comboSource.Add("1", "1");
65 comboSource.Add("2", "2");
66 comboSource.Add("3", "3");
67 comboSource.Add("4", "4");
68 comboSource.Add("5", "5");
69 comboSource.Add("6", "6");
70 comboSource.Add("7", "7");
71 comboSource.Add("8", "8");
72 comboSource.Add("9", "9");
73 comboSource.Add("10", "10");
74 comboSource.Add("11", "11");
75 comboSource.Add("12", "12");
76
77
78 cmbThangThuChi.DataSource = new BindingSource(comboSource, null);
79 cmbThangThuChi.DisplayMember = "Value";
80 cmbThangThuChi.ValueMember = "Key";
81 }
82
83 //hien thi danh sach thu chi theo ky
84 private void DanhSachThuChiCuaCuaHang()
85 {
86
87
88
89 string thag = cmbThangThuChi.SelectedValue.ToString();
90 string nam = maskedTxt_NamThuChi.Text.Trim();
91
92 if (int.Parse(thag) >= 1 && int.Parse(thag) <= 12)
93 {
94 thag = int.Parse(cmbThangThuChi.SelectedValue.ToString()).ToString("00");
95 lblThongBao.Visible = false;
96 }
97 else
98 {
99 lblThongBao.Text = "Lỗi! Tháng không đúng.";
100 lblThongBao.Visible = true;
101 cmbThangThuChi.Focus();
102 return;
103 }
104
105 if (int.Parse(nam) > 2000 && int.Parse(nam) < 2100)
106 {
107 lblThongBao.Visible = false;
108 }
109 else
110 {
111 lblThongBao.Text = "Lỗi! Năm không đúng.";
112 lblThongBao.Visible = true;
113 maskedTxt_NamThuChi.Focus();
114 return;
115 }
116
117 string nthang = nam + "-" + thag + "-01";
118 DateTime thangbc = DateTime.Parse(nthang);
119
120 DataTable dtThuC = new DataTable();
121
122 //kiem tra ngay thang tu ngay den ngay
123 string formatTuNgay = "dd/MM/yyyy";
124 DateTime dateTimeTuNgay;
125
126 string formatDenNgay = "dd/MM/yyyy";
127 DateTime dateTimeDenNgay;
128
129 int dkien = 0;
130 if (DateTime.TryParseExact(maskedTxt_TuNgay.Text, formatTuNgay, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTimeTuNgay))
131 {
132 //_tuNgay = DateTime.ParseExact(maskedTxt_TuNgay.Text, "dd/MM/yyyy", null);
133 dkien += 1;
134 }
135
136 if (DateTime.TryParseExact(maskedTxt_DenNgay.Text,formatDenNgay, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTimeDenNgay))
137 {
138 //_tuNgay = DateTime.ParseExact(maskedTxt_TuNgay.Text, "dd/MM/yyyy", null);
139 dkien += 1;
140 }
141
142 if (dkien == 2)
143 {
144 dtThuC = Controllers.BaoCaoCtrl.uct_BaoCao_HienThi_ThuChi_TuNgay_DenNgay(DateTime.ParseExact(maskedTxt_TuNgay.Text, "dd/MM/yyyy", null), DateTime.ParseExact(maskedTxt_DenNgay.Text, "dd/MM/yyyy", null)).Tables[0];
145 }
146 else
147 {
148 dtThuC = Controllers.BaoCaoCtrl.uct_BaoCao_HienThi_ThuChi(thangbc).Tables[0];
149 }
150
151
152
153 if (dtThuC.Rows.Count > 0)
154 {
155
156 txtThu_KyTruoc.Text = CauHinhHeThong.Format_SoDeHienThi(CauHinhHeThong.Format_SoDeTinhToan(dtThuC.Rows[0]["ThuKyTruoc"].ToString(), false), true);
157 txtChi_KyTruoc.Text = CauHinhHeThong.Format_SoDeHienThi(CauHinhHeThong.Format_SoDeTinhToan(dtThuC.Rows[0]["ChiKyTruoc"].ToString(), false), true);
158
159 txtThu_KyNay.Text = CauHinhHeThong.Format_SoDeHienThi(CauHinhHeThong.Format_SoDeTinhToan(dtThuC.Rows[0]["ThuKy_Nay"].ToString(), false), true);
160 txtChi_KyNay.Text = CauHinhHeThong.Format_SoDeHienThi(CauHinhHeThong.Format_SoDeTinhToan(dtThuC.Rows[0]["ChiKy_Nay"].ToString(), false), true);
161
162 txtThu_KySau.Text = CauHinhHeThong.Format_SoDeHienThi(CauHinhHeThong.Format_SoDeTinhToan(dtThuC.Rows[0]["ThuKySau"].ToString(), false), true);
163 txtChi_KySau.Text = CauHinhHeThong.Format_SoDeHienThi(CauHinhHeThong.Format_SoDeTinhToan(dtThuC.Rows[0]["ChiKySau"].ToString(), false), true);
164
165
166
167
168 }
169 else
170 {
171 txtThu_KyTruoc.Text = "0";
172 txtChi_KyTruoc.Text = "0";
173
174 txtThu_KyNay.Text = "0";
175 txtChi_KyNay.Text = "0";
176
177 txtThu_KySau.Text = "0";
178 txtChi_KySau.Text = "0";
179 }
180 }
181
182 private void btnThuChi_ThucHien_Click(object sender, EventArgs e)
183 {
184 this.DanhSachThuChiCuaCuaHang();
185 }
186
187 }
188 }